#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
//#include <math.h>
//#include <ctype.h>

int
int_pow (const int n, int i)
{
	int ret = 1; //result
	if (i == 0)
		return 1;
	while (i > 0) {
		ret *= n;
		--i;
	}
	return ret;
}


int
main ()
{
	int x, p;
	char out;
	int tmp;
	int znaki = 0, i = 0;
	freopen("tentop.in", "r", stdin);
	freopen("tentop.out", "w", stdout);
	scanf("%d %d", &p, &x);
	if (x < 0) {
		fprintf(stderr, ",less htan zero\n");
		printf("-");
		x = -x;
	}

	tmp = x;
	while (tmp != 0) {
		tmp /= p;
		++znaki;
	}
	fprintf(stderr, ",znaki == %d\n", znaki);
	if (znaki == 0) {
		printf("0");
	} else {
		while (znaki > 0) {
			--znaki;
			fprintf(stderr, ", int_pow == %d\n", int_pow(p, znaki));
			i = abs(x / int_pow(p, znaki) % p);
			fprintf(stderr, ", i = %d\n", i);
			if (i <= 9)
				printf("%c", i + '0');
			else
				printf("%c", i - 10 + 'A');
		}
	}
		

	printf("\n");
	return 0;
}
